//
//  YYSettingViewController.m
//  Unicorn
//
//  Created by xalo on 16/5/1.
//  Copyright © 2016年 bhj_jun. All rights reserved.
//

#import "YYSettingViewController.h"

#define RGBA(r,g,b,a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:(a)]

@interface YYSettingViewController ()<UIImagePickerControllerDelegate,UINavigationControllerDelegate>

@property (strong, nonatomic) IBOutlet UIButton    *LoginBtn;//登录

@property (strong, nonatomic) IBOutlet UIButton    *RegisterBtn;//注册

@property (strong, nonatomic) IBOutlet UIImageView *HeadImage;//头像

@property (strong, nonatomic) IBOutlet UIButton    *HelperBtn;//帮助与反馈

@property (strong, nonatomic) IBOutlet UIButton    *CollectBox;//收藏夹

@property (strong, nonatomic) IBOutlet UIButton    *ClearCache;//清理缓存

@property (strong, nonatomic) IBOutlet UIButton    *AboutUs;//关于我们

@property (strong, nonatomic) IBOutlet UIButton    *SingOut;//退出登录




@end

@implementation YYSettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.navigationItem.title = @"个人设置";
    
    [self settingProperty];
    
    [self addGestureToHeadimage];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


/**
 *  设置UIButton的相关属性（在layer层）
 *
 *  设置圆角 cornerRadius／masksToBounds  
 *
 *  添加边框 borderWidth／borderColor
 */
-(void)settingProperty
{
    
    //设置圆角
    self.LoginBtn.layer.cornerRadius     = 30;
    self.LoginBtn.layer.masksToBounds    = YES;
    
    self.RegisterBtn.layer.cornerRadius  = 30;
    self.RegisterBtn.layer.masksToBounds = YES;
    
    self.HeadImage.layer.cornerRadius    = 50;
    self.HeadImage.layer.masksToBounds   = YES;
    self.HeadImage.layer.borderWidth     = 15;
    self.HeadImage.layer.borderColor     = [RGBA(122, 132, 161, 0.8)CGColor];
    
    //为button设置背景色
    self.HelperBtn.backgroundColor      = [UIColor colorWithWhite:0.5 alpha:0.7];
    self.HelperBtn.layer.cornerRadius   = 10;
    self.HelperBtn.layer.masksToBounds  = YES;
    
    self.CollectBox.backgroundColor     = [UIColor colorWithWhite:0.5 alpha:0.7];
    self.CollectBox.layer.cornerRadius  = 10;
    self.CollectBox.layer.masksToBounds = YES;
    
    self.ClearCache.backgroundColor     = [UIColor colorWithWhite:0.5 alpha:0.7];
    self.ClearCache.layer.cornerRadius  = 10;
    self.ClearCache.layer.masksToBounds = YES;
    
    self.AboutUs.backgroundColor        = [UIColor colorWithWhite:0.5 alpha:0.7];
    self.AboutUs.layer.cornerRadius     = 10;
    self.AboutUs.layer.masksToBounds    = YES;
    
    self.SingOut.backgroundColor        = RGBA(214, 55, 44, 0.8);
    self.SingOut.layer.cornerRadius     = 10;
    self.SingOut.layer.masksToBounds    = YES;

    //为button添加边框
//    self.HelperBtn.layer.borderWidth     = 2.0;
//    self.HelperBtn.layer.borderColor     = [RGBA(34, 52, 66, 1.0)CGColor];
//
//    self.CollectBox.layer.borderWidth    = 2.0;
//    self.CollectBox.layer.borderColor    = [RGBA(34, 52, 66, 1.0)CGColor];
//
//    self.ClearCache.layer.borderWidth    = 2.0;
//    self.ClearCache.layer.borderColor    = [RGBA(34, 52, 66, 1.0)CGColor];
//
//    self.AboutUs.layer.borderWidth       = 2.0;
//    self.AboutUs.layer.borderColor       = [RGBA(34, 52, 66, 1.0)CGColor];
//
//    self.SingOut.layer.borderWidth       = 2.0;
//    self.SingOut.layer.borderColor       = [RGBA(214, 55, 44, 1.0)CGColor];
    
}


#pragma mark - - 为头像添加手势
-(void)addGestureToHeadimage
{
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
    [self.HeadImage addGestureRecognizer:tap];
    
}


#pragma mark - - 按钮回调事件
//登录
- (IBAction)LoginBtnAction:(UIButton *)sender {
    
    LoginViewController *loginVC = [[UIStoryboard storyboardWithName:@"SettingStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
    UINavigationController *naVC = [[UINavigationController alloc]initWithRootViewController:loginVC];
    [self presentViewController:naVC animated:YES completion:nil];
}

//注册
- (IBAction)RegisterBtnAction:(UIButton *)sender {
    
    RegisterViewController *registerVC = [[UIStoryboard storyboardWithName:@"SettingStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"RegisterViewController"];
    UINavigationController *naVC = [[UINavigationController alloc]initWithRootViewController:registerVC];
    [self presentViewController:naVC animated:YES completion:nil];
}

//帮助与反馈
- (IBAction)HelperAction:(UIButton *)sender {
    
    HelperViewController *helpVC = [[HelperViewController alloc]init];
    [self.navigationController pushViewController:helpVC animated:YES];
}

//收藏夹
- (IBAction)CollectBox:(UIButton *)sender {
    
    CollectionViewController *collectionVC = [[CollectionViewController alloc]init];
    UINavigationController *naVC = [[UINavigationController alloc]initWithRootViewController:collectionVC];
    //    [self.navigationController pushViewController:collectionVC animated:YES];
    [self.navigationController presentViewController:naVC animated:YES completion:nil];
}

//清理缓存
- (IBAction)ClearCache:(UIButton *)sender {
    
    UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"提示" message:@"确定要清除缓存?" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        NSLog(@"点击_确定_按钮后，清理缓存数据");
        
    }];
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    
    [alertC addAction:sure];
    [alertC addAction:cancel];
    [self presentViewController:alertC animated:YES completion:nil];
}

//关于我们
- (IBAction)AboutUs:(UIButton *)sender {
}

//退出登录
- (IBAction)SingOut:(UIButton *)sender {
}


//头像点击事件
-(void)tapAction:(UITapGestureRecognizer *)tap
{
    UIImagePickerController *picker = [[UIImagePickerController alloc]init];
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    picker.allowsEditing = YES;
    picker.delegate = self;
    [self presentViewController:picker animated:YES completion:^{
        
        NSLog(@"调用系统相册（入栈）");
    }];
}


#pragma mark - - 调用系统相册代理
//代理方法
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
{
    //获得要选取的图片
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
    self.HeadImage.image = image;
    [self dismissViewControllerAnimated:YES completion:^{
        
        NSLog(@"调用系统相册（出栈）");
    }];
    
}



@end
